package org.acme.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.acme.dao.SysReviewDao;
import org.acme.po.SysReview;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SysReviewServiceImpl extends ServiceImpl<SysReviewDao, SysReview> implements SysReviewService {

    @Override
    public List<SysReview> getTreeList() {
        List<SysReview> list = new ArrayList<>();
        for (SysReview sysReview : getRootList()) {
            buildPo(sysReview);
            list.add(sysReview);
        }
        return list;
    }

    @Override
    public List<SysReview> getRootList() {
        return getBaseMapper().getRootList();
    }

    @Override
    public List<SysReview> getListByPId(String pid) {
        return getBaseMapper().getListByPId(pid);
    }

    @Override
    public SysReview buildPo(SysReview sysReview) {
        List<SysReview> list = getListByPId(sysReview.getId());
        if (!list.isEmpty()){
            sysReview.getChildren().addAll(list);
        }
        for (SysReview review : list) {
            buildPo(review);
        }
        return sysReview;
    }
}
